require "preDefine"

log = log or {}

function log.append(str)
	if not DEF_WRITE_LOG then
		return
	end

	if cc.PLATFORM_OS_ANDROID == g_targetPlatform then
	    logpath = "/mnt/sdcard/"
	elseif cc.PLATFORM_OS_WINDOWS == g_targetPlatform then
		logpath = cc.FileUtils:getInstance():getWritablePath()
	end

	logpath = logpath.."lua_error.log"
    
	local f = io.open(logpath, "r")
	if not f then
	   f = io.open(logpath, "a")
	   f:close()
	   f = io.open(logpath, "r")
	end
	local text = f:read("*all")
	f:close()

    local tm = os.date()
	text = text.."[[Lua Error Log]]:("..tostring(tm)..")\n"
	text = text..str.."\n\n"

	f = io.open(logpath, "w")
	f:write(text)
	f:close()
end